package com.zz.ui_demo_wedgit.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.zz.ui_demo_wedgit.sqlite.FeedReaderContract.FeedEntry;

import androidx.annotation.Nullable;
//数据库的创建
public class FeedReaderDBHelper extends SQLiteOpenHelper {
    public static final int DATABASE_VERSION =1;
    public static final String DATABASE_NAME = "FeedReader.db";//存放文件的名字
    //数据实体表的定义方式
    private static final String SQL_CREATE_ENTRIES =  "CREATE TABLE "
            + FeedEntry.TABLE_NAME + "("
            + FeedEntry._ID + " INTEGER PRIMARY KEY, "
            + FeedEntry.COLUMN_NAME_TITLE + " TEXT, "
            + FeedEntry.COLUMN_NAME_SUBTITLE + " TEXT)";

    private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + FeedEntry.TABLE_NAME;

    public FeedReaderDBHelper(@Nullable Context context)  {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);//定义数据库的名字，数据库的版本
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTRIES);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_ENTRIES);
        onCreate(db);
    }
}
